﻿using Farming.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Farming.EntityFarmworkCore
{
    public class FarmingDbContext : DbContext
    {
        public FarmingDbContext(DbContextOptions options) : base(options)
        {
        }
        public DbSet<Admin> Admins {  get; set; }
        public DbSet<Traceability> Traceabilities { get; set; }
        public DbSet<AccesstInfo> AccesstInfos { get; set; }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Admin>().HasQueryFilter(x => !x.IsDel);
            modelBuilder.Entity<Traceability>().HasQueryFilter(x => !x.IsDel);
            base.OnModelCreating(modelBuilder);
            //modelBuilder.Entity<Admin>(m =>
            //{
            //    m.Property(x => x.UserName).HasMaxLength(50).IsRequired();
            //    m.Property(x => x.PassWord).HasMaxLength(50).IsRequired();
            //    m.Property(x => x.LastLoginTime).HasMaxLength(50);
            //});
            ////数据播种
            //modelBuilder.Entity<Admin>().HasData(
            //    new Admin
            //    {
            //        UserName = "Admin",
            //        PassWord = Guid.NewGuid().ToString("n"),
            //        AdminId = 1,
            //        CreateById = 1,
            //        CreateByName = "Admin",
            //        CreateTime = DateTime.Now,
            //        IsDel = false
            //    },
            //    new Admin
            //    {
            //        UserName = "lisi",
            //        PassWord = Guid.NewGuid().ToString("n"),
            //        AdminId = 2,
            //        CreateById = 1,
            //        CreateByName = "Admin",
            //        CreateTime = DateTime.Now.AddDays(6),
            //        IsDel = false
            //    });
            //base.OnModelCreating(modelBuilder);


        }

    }
}
